package com.ruoyi.merchant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.MerchantVerification;
import com.ruoyi.merchant.service.IMerchantVerificationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户认证Controller
 * 
 * @author ruoyi
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/verification")
public class MerchantVerificationController extends BaseController
{
    @Autowired
    private IMerchantVerificationService merchantVerificationService;

    /**
     * 查询商户认证列表
     */
    @RequiresPermissions("merchant:verification:list")
    @GetMapping("/list")
    public TableDataInfo list(MerchantVerification merchantVerification)
    {
        startPage();
        List<MerchantVerification> list = merchantVerificationService.selectMerchantVerificationList(merchantVerification);
        return getDataTable(list);
    }

    /**
     * 导出商户认证列表
     */
    @RequiresPermissions("merchant:verification:export")
    @Log(title = "商户认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantVerification merchantVerification)
    {
        List<MerchantVerification> list = merchantVerificationService.selectMerchantVerificationList(merchantVerification);
        ExcelUtil<MerchantVerification> util = new ExcelUtil<MerchantVerification>(MerchantVerification.class);
        util.exportExcel(response, list, "商户认证数据");
    }

    /**
     * 获取商户认证详细信息
     */
    @RequiresPermissions("merchant:verification:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantVerificationService.selectMerchantVerificationById(id));
    }

    /**
     * 新增商户认证
     */
    @RequiresPermissions("merchant:verification:add")
    @Log(title = "商户认证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantVerification merchantVerification)
    {
        return toAjax(merchantVerificationService.insertMerchantVerification(merchantVerification));
    }
@InnerAuth
    @Log(title = "商户认证", businessType = BusinessType.INSERT)
    @PostMapping("MerchantVerificationAdd")
    public AjaxResult MerchantVerificationAdd(@RequestBody MerchantVerification merchantVerification)
    {
        return toAjax(merchantVerificationService.insertMerchantVerification(merchantVerification));
    }

    /**
     * 修改商户认证
     */
    @RequiresPermissions("merchant:verification:edit")
    @Log(title = "商户认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantVerification merchantVerification)
    {
        return toAjax(merchantVerificationService.updateMerchantVerification(merchantVerification));
    }

    /**
     * 删除商户认证
     */
    @RequiresPermissions("merchant:verification:remove")
    @Log(title = "商户认证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantVerificationService.deleteMerchantVerificationByIds(ids));
    }
@InnerAuth
    @GetMapping("/getMerchantByPhone")
    public MerchantVerification getMerchantByPhone(@RequestParam("phone") String phone)
    {
        MerchantVerification phone1 = merchantVerificationService.getMerchantVerificatinByPhone(phone);
        return phone1;
    }
@InnerAuth
    @GetMapping("/getlist")
    public    List<MerchantVerification> getlist(MerchantVerification merchantVerification)
    {
        return merchantVerificationService.selectMerchantVerificationList(merchantVerification);
    }

}
